package com.villaday.idf.custom.bannerUtil;

import androidx.viewpager.widget.ViewPager;
import android.view.View;

import com.villaday.idf.custom.bannerUtil.uiType.AccordionPageTransformer;
import com.villaday.idf.custom.bannerUtil.uiType.AlphaPageTransformer;
import com.villaday.idf.custom.bannerUtil.uiType.DefaultPageTransformer;
import com.villaday.idf.custom.bannerUtil.uiType.FadePageTransformer;
import com.villaday.idf.custom.bannerUtil.uiType.TransitionEffect;


/**
 * Created by Administrator on 2017/3/27.
 */

public abstract class BannerPageTransformer implements ViewPager.PageTransformer {

    public void transformPage(View view, float position) {
        if (position < -1.0f) {
            // [-Infinity,-1)
            // This page is way off-screen to the left.
            handleInvisiblePage(view, position);
        } else if (position <= 0.0f) {
            // [-1,0]
            // Use the default slide transition when moving to the left page
            handleLeftPage(view, position);
        } else if (position <= 1.0f) {
            // (0,1]
            handleRightPage(view, position);
        } else {
            // (1,+Infinity]
            // This page is way off-screen to the right.
            handleInvisiblePage(view, position);
        }
    }

    public abstract void handleInvisiblePage(View view, float position);

    public abstract void handleLeftPage(View view, float position);

    public abstract void handleRightPage(View view, float position);

    public static ViewPager.PageTransformer getPageTransformer(TransitionEffect effect) {
        switch (effect) {
            case Default:
                return new DefaultPageTransformer();
            case Alpha:
                return new AlphaPageTransformer();
            case Accordion:
                return new AccordionPageTransformer();
            case Fade:
                return new FadePageTransformer();
            default:
                return new DefaultPageTransformer();
        }
    }
}
